package com.hanbang.maige.widget.ninegridimageview;

import android.content.Context;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.hanbang.maige.R;
import com.hanbang.maige.utils.http.httpquest.HttpLocalUtils;

import java.util.List;

/**
 * Created by Jaeger on 16/2/24.
 * <p>
 * Email: chjie.jaeger@gamil.com
 * GitHub: https://github.com/laobie
 */
public abstract class NineGridImageViewAdapter<T> {

    protected abstract void onDisplayImage(Context context, ImageView imageView, T t);

    protected void onDisplayImageOne(Context context, ImageView imageView, T t) {
        if (t instanceof String) {
            glideOne(context, imageView, (String) t);
        }
    }

    protected void glideOne(Context context, ImageView imageView, String t) {
        int width = imageView.getLayoutParams().width;
        Glide.with(context).load(HttpLocalUtils.getHttpFileUrl(t))
                .sizeMultiplier(0.8f)
                .crossFade()
                .fitCenter()
                .override(width, width)
                .placeholder(R.mipmap.default_1_1)
                .error(R.mipmap.default_1_1)
                .diskCacheStrategy(DiskCacheStrategy.ALL).into(imageView);
    }

    protected void onItemImageClick(Context context, int index, List<T> list) {
    }

    protected ImageView generateImageView(Context context) {
        GridImageView imageView = new GridImageView(context);
        imageView.setBackgroundColor(0xff0000);
        imageView.setScaleType(ImageView.ScaleType.FIT_START);
        //imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
        return imageView;
    }
}